<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>
        //对象
        function People() {
            this.name = 'trump'
        }
        People.prototype.age = 70;
        People.prototype.sayHi = function () {
            //原型里面的this 代表还是当前对象p1
            console.log(this.name);  //构造函数的原型对象里面  peototye原型对象
        }
        var p1 = new People();
        p1.sayHi()
        console.log(p1.age);
        console.log(p1);


        //数组
        Array.prototype.sum = function ()
        //this代表创建的数组对象
        {
            var sum = 0
            for (var i = 0; i < this.length; i++) {
                sum += this[i]
            }
            return sum
        }
        var arr = [10, 20, 30, 40, 50, 60]
        console.log('求数组的和', arr.sum());  //调用数组用原型对象prototype创建的方法


        //数组
        var arr1 = new Array()  //数组  对象
        arr1.username = 'trump'
        Array.prototype.counter = function () {
            console.log('这是counter函数');
        }
        var arr2 = new Array()
        console.log('arr1 username=>', arr1.username);  //trump
        console.log('arr2 username=>', arr2.username);  //undefined

        console.log('arr1 counter=>');
        arr1.counter()   //有

        console.log('arr2 counter=>');
        arr2.counter()  //有
    </script>

</body>

</html>